home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Include / Memory.au3 < prev    next >
Encoding:
Text File  |  2007-09-08  |  24.7 KB  |  408 lines

  1. #include-once
  2. ; ====================================================================================================
  3. ; AutoIt Version : 3.2.+++
  4. ; Author ........: Paul Campbell
  5. ; Modified.......: Gary Frost
  6. ; Description ...: Memory management routines
  7. ; Notes .........:
  8. ; ====================================================================================================
  9.  
  10. ; ====================================================================================================
  11. ; MEMMAP Definition
  12. ; ====================================================================================================
  13.  
  14. Global Const $MEM_MAP = "uint;uint;ptr"
  15.  
  16. ; ====================================================================================================
  17. ; MemMap Position Constants
  18. ; ====================================================================================================
  19.  
  20. Global Const $MEM_MAP_HPROC = 1
  21. Global Const $MEM_MAP_ISIZE = 2
  22. Global Const $MEM_MAP_PMEM = 3
  23.  
  24. ; ====================================================================================================
  25. ; VirtualAlloc Allocation Type Constants
  26. ; ====================================================================================================
  27.  
  28. ;Global Const $MEM_COMMIT = 0x00001000
  29. ;Global Const $MEM_RESERVE = 0x00002000
  30. ;Global Const $MEM_TOP_DOWN = 0x00100000
  31. ;Global Const $MEM_SHARED = 0x08000000
  32.  
  33. ; ====================================================================================================
  34. ; VirtualFree FreeType Constants
  35. ; ====================================================================================================
  36.  
  37. ;Global Const $MEM_DECOMMIT = 0x00004000
  38. ;Global Const $MEM_RELEASE = 0x00008000
  39.  
  40. ; ====================================================================================================
  41. ; VirtualAlloc Protection Constants
  42. ; ====================================================================================================
  43.  
  44. ;Global Const $PAGE_NOACCESS = 0x00000001
  45. ;Global Const $PAGE_READONLY = 0x00000002
  46. ;Global Const $PAGE_READWRITE = 0x00000004
  47. ;Global Const $PAGE_EXECUTE = 0x00000010
  48. ;Global Const $PAGE_EXECUTE_READ = 0x00000020
  49. ;Global Const $PAGE_EXECUTE_READWRITE = 0x00000040
  50. ;Global Const $PAGE_GUARD = 0x00000100
  51. ;Global Const $PAGE_NOCACHE = 0x00000200
  52.  
  53. ; ====================================================================================================
  54. ; OpenProcess Access Constants
  55. ; ====================================================================================================
  56.  
  57. ;Global Const $PROCESS_TERMINATE = 0x00000001
  58. ;Global Const $PROCESS_CREATE_THREAD = 0x00000002
  59. ;Global Const $PROCESS_VM_OPERATION = 0x00000008
  60. ;Global Const $PROCESS_VM_READ = 0x00000010
  61. ;Global Const $PROCESS_VM_WRITE = 0x00000020
  62. ;Global Const $PROCESS_DUP_HANDLE = 0x00000040
  63. ;Global Const $PROCESS_CREATE_PROCESS = 0x00000080
  64. ;Global Const $PROCESS_SET_INFORMATION = 0x00000200
  65. ;Global Const $PROCESS_QUERY_INFORMATION = 0x00000400
  66. ;Global Const $SYNCHRONIZE = 0x00100000
  67. ;Global Const $PROCESS_ALL_ACCESS = 0x001F0FFF
  68.  
  69. ; ====================================================================================================
  70. ; Description ..: Releases a memory map structure
  71. ; Parameters ...: $rMemMap      - The MEM_MAP structure to release
  72. ; Return values : True  - Success
  73. ;                 False - Function failed
  74. ; Notes ........: $rMemMap must have first been initialized with a call to _MemInit
  75. ; ====================================================================================================
  76. Func _MemFree(ByRef $rMemMap)
  77.     Local $hProcess
  78.     Local $pMemory
  79.     Local $bResult
  80.     Local $MEM_RELEASE = 0x00008000
  81.  
  82.     $hProcess = DllStructGetData($rMemMap, $MEM_MAP_HPROC)
  83.     $pMemory = DllStructGetData($rMemMap, $MEM_MAP_PMEM)
  84.     Switch @OSVersion
  85.         Case "WIN_ME", "WIN_98", "WIN_95"
  86.             $bResult = _VirtualFree($pMemory, 0, $MEM_RELEASE)
  87.         Case Else
  88.             $bResult = _VirtualFreeEx($hProcess, $pMemory, 0, $MEM_RELEASE)
  89.     EndSwitch
  90.     _CloseHandle($hProcess)
  91.     $rMemMap = 0
  92.     Return $bResult
  93. EndFunc   ;==>_MemFree
  94.  
  95. ; ====================================================================================================
  96. ; Description ..: Closes an open object handle
  97. ; Parameters ...: $hObject      - Handle of object to close
  98. ; Return values : Success - True
  99. ;                 Failure - False
  100. ; ====================================================================================================
  101. Func _CloseHandle($hObject)
  102.     Local $aResult = DllCall("Kernel32.dll", "int", "CloseHandle", "int", $hObject)
  103.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  104.     Return $aResult[0]
  105. EndFunc   ;==>_CloseHandle
  106.  
  107. ; ====================================================================================================
  108. ; Description ..: Reserves or commits a region of pages in the virtual address space  of  the  calling
  109. ;                 process. Memory allocated by this function is automatically initialized to zero.
  110. ; Parameters ...: $pAddress     - Specifies the desired starting address of the  region  to  allocate.
  111. ;                   If the memory is being reserved, the specified address is rounded down to the next
  112. ;                   64-kilobyte boundary. If the memory is already reserved and  is  being  committed,
  113. ;                   the address is rounded down to the next page boundary. To determine the size of a
  114. ;                   page on the host computer, use the GetSystemInfo function.   If this parameter is
  115. ;                   0, the system determines where to allocate the region.
  116. ;                 $iSize        - Specifies the size, in bytes, of  the  region.    If  the  $pAddress
  117. ;                   parameter is 0, this value is rounded up to the next page boundary. Otherwise, the
  118. ;                   allocated pages include all pages containing one or more bytes in the  range  from
  119. ;                   $pAddress to ($pAddress + $iSize).   This means that a 2-byte range  straddling  a
  120. ;                   page boundary causes both pages to be included in the allocated region.
  121. ;                 $iAllocation  - Specifies the type of allocation:
  122. ;                   MEM_COMMIT   - Allocates physical storage in memory or in the paging file on  disk
  123. ;                     for the specified region of pages.  An attempt to commit  an  already  committed
  124. ;                     page will not cause the function to fail.  This means that a range of  committed
  125. ;                     or decommitted pages can be committed without having to worry about a failure.
  126. ;                   MEM_RESERVE  - Reserves a range of the process's  virtual  address  space  without
  127. ;                     allocating any physical storage.  The reserved range cannot be used by any other
  128. ;                     allocation operations until it is released.   Reserved pages can be committed in
  129. ;                     subsequent calls to VirtualAlloc.
  130. ;                   MEM_TOP_DOWN - Allocates memory at the highest possible address.
  131. ;                 $iProtect     - Type of access protection:
  132. ;                   PAGE_READONLY          - Enables read access to the committed region of pages.  An
  133. ;                     attempt to write to the committed region results in an access violation.
  134. ;                   PAGE_READWRITE         - Enables read and write access to the committed region
  135. ;                   PAGE_EXECUTE           - Enables execute access to the committed region
  136. ;                   PAGE_EXECUTE_READ      - Enables execute and read access to the committed region
  137. ;                   PAGE_EXECUTE_READWRITE - Enables execute, read, and write access to the  committed
  138. ;                     region of pages.
  139. ;                   PAGE_GUARD             - Pages in the region become guard pages.   Any attempt  to
  140. ;                     read from or write to a guard page  causes  the  operating  system  to  raise  a
  141. ;                     STATUS_GUARD_PAGE exception and turn off the guard page status.
  142. ;                   PAGE_NOACCESS          - Disables all access to the committed region of pages
  143. ;                   PAGE_NOCACHE           - Allows no caching of the committed regions of pages.  The
  144. ;                     hardware attributes for the physical memory should be specified as "no cache."
  145. ; Return values : Memory address pointer
  146. ; ====================================================================================================
  147. Func _VirtualAlloc($pAddress, $iSize, $iAllocation, $iProtect)
  148.     Local $aResult = DllCall("Kernel32.dll", "ptr", "VirtualAlloc", "ptr", $pAddress, "int", $iSize, "int", $iAllocation, "int", $iProtect)
  149.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  150.     Return $aResult[0]
  151. EndFunc   ;==>_VirtualAlloc
  152.  
  153. ; ====================================================================================================
  154. ; Description ..: Reserves a region of memory within the virtual address space of a specified process
  155. ; Parameters ...: $hProcess     - Handle to a process.   The function allocates memory in the  virtual
  156. ;                   address space of this process.   You must have PROCESS_VM_OPERATION access to  the
  157. ;                   process. If you do not, the function fails.
  158. ;                 $pAddress     - Same as VirtualAlloc
  159. ;                 $iSize        - Same as VirtualAlloc
  160. ;                 $iAllocation  - Same as VirtualAlloc
  161. ;                 $iProtect     - Same as VirtualAlloc
  162. ; Return values : Memory address pointer
  163. ; ====================================================================================================
  164. Func _VirtualAllocEx($hProcess, $pAddress, $iSize, $iAllocation, $iProtect)
  165.     Local $aResult = DllCall("Kernel32.dll", "ptr", "VirtualAllocEx", "int", $hProcess, "ptr", $pAddress, "int", $iSize, "int", $iAllocation, "int", $iProtect)
  166.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  167.     Return $aResult[0]
  168. EndFunc   ;==>_VirtualAllocEx
  169.  
  170. ; ====================================================================================================
  171. ; Description ..: Releases a region of pages within the virtual address space of a process
  172. ; Parameters ...: $pAddress     - Points to the base address of the region of pages to be  freed.   If
  173. ;                   the $iFreeType parameter includes MEM_RELEASE this  parameter  must  be  the  base
  174. ;                   address returned by VirtualAlloc when the region of pages was reserved.
  175. ;                 $iSize        - Specifies the size, in bytes, of the region to  be  freed.   If  the
  176. ;                   $iFreeType parameter includes the MEM_RELEASE flag, this parameter must  be  zero.
  177. ;                   Otherwise, the region of affected pages includes all pages containing one or  more
  178. ;                   bytes in the range from the  $pAddress  parameter  to  ($pAddress + $iSize).  This
  179. ;                   means that a 2-byte range straddling a page boundary causes both pages to be freed.
  180. ;                 $iFreeType    - Specifies the type of free operation:
  181. ;                   MEM_DECOMMIT - Decommits the specified region of committed pages.   An attempt  to
  182. ;                     decommit an uncommitted page will not cause the function  to  fail.  This  means
  183. ;                     that a range of committed  or  uncommitted  pages  can  be  decommitted  without
  184. ;                     having to worry about a failure.
  185. ;                   MEM_RELEASE  - Releases the specified region of reserved pages.   If this flag  is
  186. ;                     specified, the $iSize parameter must be zero or the function fails.
  187. ; Return values : Success - True
  188. ;                 Failure - False
  189. ; ====================================================================================================
  190. Func _VirtualFree($pAddress, $iSize, $iFreeType)
  191.     Local $aResult = DllCall("Kernel32.dll", "ptr", "VirtualFree", "ptr", $pAddress, "int", $iSize, "int", $iFreeType)
  192.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  193.     Return $aResult[0]
  194. EndFunc   ;==>_VirtualFree
  195.  
  196. ; ====================================================================================================
  197. ; Description ..: Releases a region of pages within the virtual address space of a process
  198. ; Parameters ...: $hProcess     - Handle to a process.   The function frees memory within the  virtual
  199. ;                   address space of this process.   You must have PROCESS_VM_OPERATION access to this
  200. ;                   process. If you do not, the function fails.
  201. ;                 $pAddress     - See _VirtualFree
  202. ;                 $iSize        - See _VirtualFree
  203. ;                 $iFreeType    - See _VirtualFree
  204. ; Return values : Success - True
  205. ;                 Failure - False
  206. ; ====================================================================================================
  207. Func _VirtualFreeEx($hProcess, $pAddress, $iSize, $iFreeType)
  208.     Local $aResult = DllCall("Kernel32.dll", "ptr", "VirtualFreeEx", "hwnd", $hProcess, "ptr", $pAddress, "int", $iSize, "int", $iFreeType)
  209.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  210.     Return $aResult[0]
  211. EndFunc   ;==>_VirtualFreeEx
  212.  
  213. ; ====================================================================================================
  214. ; Description ..: Retrieves the identifier of the thread that created the  specified  window  and  the
  215. ;                 identifier of the process that created the window.
  216. ; Parameters ...: $hWnd         - Window handle
  217. ;                 $iProcessID   - Process ID of the specified window.  If this parameter is not 0, the
  218. ;                                 function copies the identifier of the process otherwise it does not.
  219. ; Return values : Thread ID of the specified window
  220. ; ====================================================================================================
  221. Func _GetWindowThreadProcessId($hWnd, ByRef $iProcessID)
  222.     Local $rProcessID, $aResult
  223.     $rProcessID = DllStructCreate("int")
  224.     $aResult = DllCall("User32.dll", "int", "GetWindowThreadProcessId", "hwnd", $hWnd, "ptr", DllStructGetPtr($rProcessID))
  225.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  226.     $iProcessID = DllStructGetData($rProcessID, 1)
  227.     Return $aResult[0]
  228. EndFunc   ;==>_GetWindowThreadProcessId
  229.  
  230. ; ====================================================================================================
  231. ; Description ..: Returns a handle of an existing process object
  232. ; Parameters ...: $iAccess      - Specifies the access to the process object
  233. ;                 $bInherit     - Specifies whether the returned handle can be inherited
  234. ;                 $iProcessID   - Specifies the process identifier of the process to open
  235. ; Return values : Open process handle to the object
  236. ; ====================================================================================================
  237. Func _OpenProcess($iAccess, $bInherit, $iProcessID)
  238.     Local $aResult = DllCall("Kernel32.Dll", "int", "OpenProcess", "int", $iAccess, "int", $bInherit, "int", $iProcessID)
  239.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  240.     Return $aResult[0]
  241. EndFunc   ;==>_OpenProcess
  242.  
  243. ; ====================================================================================================
  244. ; Description ..: Read memory in a specified process
  245. ; Parameters ...: $hProcess     - Identifies an open handle of a process whose memory  is  read.   The
  246. ;                   handle must have PROCESS_VM_READ access to the process.
  247. ;                 $pBaseAddress - Points to the base address in the  specified  process  to  be  read.
  248. ;                   Before any data transfer occurs, the system verifies that all  data  in  the  base
  249. ;                   address and memory of the specified size is accessible for read access. If this is
  250. ;                   the case the function proceeds otherwise the function fails.
  251. ;                 $pBuffer      - Points to a buffer that receives the contents from the address space
  252. ;                   of the specified process.
  253. ;                 $iSize        - Specifies the requested number of bytes to read from  the  specified
  254. ;                   process.
  255. ;                 $iBytesRead   - The actual number of bytes transferred into the specified buffer. If
  256. ;                   $iBytesRead is 0, the parameter is ignored.
  257. ; Return values : Success - True
  258. ;                 Failure - False
  259. ; ====================================================================================================
  260. Func _ReadProcessMemory($hProcess, $pBaseAddress, $pBuffer, $iSize, ByRef $iBytesRead)
  261.     Local $rBytesRead = DllStructCreate("int")
  262.     Local $aResult = DllCall("Kernel32.dll", "int", "ReadProcessMemory", "int", $hProcess, "int", $pBaseAddress, _
  263.             "ptr", $pBuffer, "int", $iSize, "ptr", DllStructGetPtr($rBytesRead))
  264.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  265.     $iBytesRead = DllStructGetData($rBytesRead, 1)
  266.     $rBytesRead = 0
  267.     Return $aResult[0]
  268. EndFunc   ;==>_ReadProcessMemory
  269.  
  270. ; ====================================================================================================
  271. ; Description ..: Writes memory in a specified process
  272. ; Parameters ...: $hProcess     - Identifies an open handle to a process whose memory is to be written
  273. ;                   to.   The handle must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the
  274. ;                   process.
  275. ;                 $pBaseAddress - Points to the base address in the specified process to be written to
  276. ;                   Before any data transfer occurs, the system verifies that all  data  in  the  base
  277. ;                   address and memory of the specified size is accessible for write access. If so the
  278. ;                   function proceeds otherwise the function fails.
  279. ;                 $pBuffer      - Points to the buffer that supplies  data  to  be  written  into  the
  280. ;                   address space of the specified process.
  281. ;                 $iSize        - Specifies the number of bytes to write into the specified process
  282. ;                 $iBytesWritten- The actual number of bytes transferred into the  specified  process.
  283. ;                   This parameter is optional. If $iBytesWritten is 0, the parameter is ignored.
  284. ; Return values : Success - True
  285. ;                 Failure - False
  286. ; ====================================================================================================
  287. Func _WriteProcessMemory($hProcess, $pBaseAddress, $pBuffer, $iSize, ByRef $iBytesWritten)
  288.     Local $rBytesWritten = DllStructCreate("int")
  289.     Local $aResult = DllCall("Kernel32.dll", "int", "WriteProcessMemory", "int", $hProcess, "int", $pBaseAddress, _
  290.             "ptr", $pBuffer, "int", $iSize, "int", DllStructGetPtr($rBytesWritten))
  291.     If @error Or Not IsArray($aResult) Then Return SetError(-1, -1, 0)
  292.     $iBytesWritten = DllStructGetData($rBytesWritten, 1)
  293.     $rBytesWritten = 0
  294.     Return $aResult[0]
  295. EndFunc   ;==>_WriteProcessMemory
  296.  
  297.  
  298. ; ====================================================================================================
  299. ; Description ..: Initializes a memory map structure based on a windows handle
  300. ; Parameters ...: $hWnd         - Window handle of the process where memory will be mapped
  301. ;                 $iSize        - Size in bytes of memory space
  302. ;                 $rMemMap      - MEM_MAP structure
  303. ;                 $pAddress     - Pointer that specifies a desired starting address for the region  of
  304. ;                   pages that you want to allocate.  If you are reserving memory, the function rounds
  305. ;                   this address down to the nearest 64K  boundary.  If you are committing memory that
  306. ;                   is already reserved, the function rounds this address down  to  the  nearest  page
  307. ;                   boundary. To determine the size of a page, use  the  GetSystemInfo  function.   If
  308. ;                   $pAddress is 0, the function will determine where to allocate the region.
  309. ; Return values : Pointer to reserved memory
  310. ; ====================================================================================================
  311. Func _MemInit($hWnd, $iSize, ByRef $rMemMap, $pAddress = 0)
  312.     Local $iAccess, $iAllocation
  313.     Local $pMemory, $hProcess
  314.     Local $iProcessID
  315.     Local $PROCESS_VM_OPERATION = 0x00000008
  316.     Local $PROCESS_VM_READ = 0x00000010
  317.     Local $PROCESS_VM_WRITE = 0x00000020
  318.     Local $MEM_RESERVE = 0x00002000
  319.     Local $MEM_COMMIT = 0x00001000
  320.     Local $MEM_SHARED = 0x08000000
  321.     Local $PAGE_READWRITE = 0x00000004
  322. ;~     , $iThreadID
  323.  
  324. ;~     $iThreadID = _GetWindowThreadProcessId($hWnd, $iProcessID)
  325.     _GetWindowThreadProcessId($hWnd, $iProcessID)
  326.     $iAccess = BitOR($PROCESS_VM_OPERATION, $PROCESS_VM_READ, $PROCESS_VM_WRITE)
  327.     $hProcess = _OpenProcess($iAccess, False, $iProcessID)
  328.     Switch @OSVersion
  329.         Case "WIN_ME", "WIN_98", "WIN_95"
  330.             $iAllocation = BitOR($MEM_RESERVE, $MEM_COMMIT, $MEM_SHARED)
  331.             $pMemory = _VirtualAlloc($pAddress, $iSize, $iAllocation, $PAGE_READWRITE)
  332.         Case Else
  333.             $iAllocation = BitOR($MEM_RESERVE, $MEM_COMMIT)
  334.             $pMemory = _VirtualAllocEx($hProcess, $pAddress, $iSize, $iAllocation, $PAGE_READWRITE)
  335.     EndSwitch
  336.     If @error Then Return SetError(-1, -1, 0)
  337.     $rMemMap = DllStructCreate($MEM_MAP)
  338.     DllStructSetData($rMemMap, $MEM_MAP_HPROC, $hProcess)
  339.     DllStructSetData($rMemMap, $MEM_MAP_ISIZE, $iSize)
  340.     DllStructSetData($rMemMap, $MEM_MAP_PMEM, $pMemory)
  341.     Return $pMemory
  342. EndFunc   ;==>_MemInit
  343.  
  344. ; ====================================================================================================
  345. ; Description ..: Transfer memory from external address space to internal address space
  346. ; Parameters ...: $rMemMap      - MEM_MAP structure
  347. ;                 $pSrce        - Pointer to external memory
  348. ;                 $pDest        - Pointer to internal memory
  349. ;                 $iSize        - Size in bytes of memory to read
  350. ; Return values : True  - Success
  351. ;                 False - Failure
  352. ; ====================================================================================================
  353. Func _MemRead($rMemMap, $pSrce, $pDest, $iSize)
  354.     Local $hProcess
  355.     Local $iWritten
  356.  
  357.     $hProcess = DllStructGetData($rMemMap, $MEM_MAP_HPROC)
  358.     Return _ReadProcessMemory($hProcess, $pSrce, $pDest, $iSize, $iWritten)
  359. EndFunc   ;==>_MemRead
  360.  
  361. ; ====================================================================================================
  362. ; Description ..: Transfer memory to external address space from internal address space
  363. ; Parameters ...: $rMemMap      - MEM_MAP structure
  364. ;                 $pSrce        - Pointer to internal memory
  365. ;                 $pDest        - Pointer to external memory.    If this value is 0, then  the  memory
  366. ;                   pointer from $rMemMap will be used.
  367. ;                 $iSize        - Size in bytes of memory to write.  If this value is 0, then the size
  368. ;                   value from $rMemMap will be used.
  369. ; Return values : True  - Success
  370. ;                 False - Failure
  371. ; ====================================================================================================
  372. Func _MemWrite($rMemMap, $pSrce, $pDest = 0, $iSize = 0)
  373.     Local $hProcess
  374.     Local $iWritten
  375.  
  376.     If $pDest = 0 Then
  377.         $pDest = DllStructGetData($rMemMap, $MEM_MAP_PMEM)
  378.     EndIf
  379.     If $iSize = 0 Then
  380.         $iSize = DllStructGetData($rMemMap, $MEM_MAP_ISIZE)
  381.     EndIf
  382.     $hProcess = DllStructGetData($rMemMap, $MEM_MAP_HPROC)
  383.     Return _WriteProcessMemory($hProcess, $pDest, $pSrce, $iSize, $iWritten)
  384. EndFunc   ;==>_MemWrite
  385.  
  386. ; ====================================================================================================
  387. ; Description ..: Maps a character string to a wide-character (Unicode) string
  388. ; Parameters ...: $sText        - Text to be converted
  389. ;                 $iCodePage    - Specifies the code page to be used to perform the conversion:
  390. ;                   CP_ACP   - ANSI code page
  391. ;                   CP_MACCP - Macintosh code page
  392. ;                   CP_OEMCP - OEM code page
  393. ;                 $iFlags       - A set of bit flags that indicate whether to translate to precomposed
  394. ;                   or composite wide characters:
  395. ;                   MB_PRECOMPOSED   - Always use precomposed characters
  396. ;                   MB_COMPOSITE     - Always use composite characters
  397. ;                   MB_USEGLYPHCHARS - Use glyph characters instead of control characters
  398. ; Return values : Structure that contains the Unicode character string
  399. ; ====================================================================================================
  400. Func _MultiByteToWideChar($s_Text, $i_CodePage = 0, $i_Flags = 1)
  401.     Local $iBuffLen = StringLen($s_Text)
  402.     Local $rUnicode = DllStructCreate("byte[" & ($iBuffLen * 2) & "]")
  403.     Local $pUnicode = DllStructGetPtr($rUnicode)
  404.     DllCall("Kernel32.dll", "int", "MultiByteToWideChar", "int", $i_CodePage, "int", $i_Flags, _
  405.             "str", $s_Text, "int", $iBuffLen, "ptr", $pUnicode, "int", $iBuffLen * 2)
  406.     If @error Then Return SetError(-1, -1, 0)
  407.     Return DllStructGetData($rUnicode, 1)
  408. EndFunc   ;==>_MultiByteToWideChar